<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/js/jquery.easyui.min.js"></script>
        <style type="text/css">
            body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
            #l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
            #r-result{height:100%;width:20%;float:left;}
        </style>
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=bWbtjArhHf2DpxB0dHsagQ7s"></script>
        <title>设置覆盖物的显示与隐藏</title>
    </head>
    <body>

        <div id="l-map"></div>
        <div id="r-result">
            <input type="button"  value="保存标注坐标" onclick="submitpoint()" />
        </div>
        <script type="text/javascript">
            var map = new BMap.Map("l-map");
            map.enableScrollWheelZoom(true);
                    map.centerAndZoom(new BMap.Point({$vo.Latitude}, {$vo.Longitude}), 15);
                    //map.centerAndZoom("上海",15); 
                    var marker;
                    marker = new BMap.Marker(new BMap.Point({$vo.Latitude}, {$vo.Longitude}));
                    map.addOverlay(marker);
            var contextMenu = new BMap.ContextMenu();
            var txtMenuItem = [
                {
                    text: '放大',
                    callback: function() {
                        map.zoomIn()
                    }
                },
                {
                    text: '缩小',
                    callback: function() {
                        map.zoomOut()
                    }
                },
                {
                    text: '放置到最大级',
                    callback: function() {
                        map.setZoom(18)
                    }
                },
                {
                    text: '在此添加标注',
                    callback: function(p) {
                        map.clearOverlays();
                        marker = new BMap.Marker(p), px = map.pointToPixel(p);
                        map.addOverlay(marker);
                        marker.enableDragging();    //可拖拽
                    }
                }
            ];

            for (var i = 0; i < txtMenuItem.length; i++) {
                contextMenu.addItem(new BMap.MenuItem(txtMenuItem[i].text, txtMenuItem[i].callback, 100));
                if (i == 1 || i == 3) {
                    contextMenu.addSeparator();
                }
            }
            map.addContextMenu(contextMenu);
            function submitpoint() {
                if (marker == null) {
                    alert("没有添加标注！");
                }
                else {
                    var p = marker.getPosition();
                    //alert("marker的位置是" + p.lng + "," + p.lat); 

                    $.post("{:U('Map/SetBuildingPoint')}", {Lat: p.lng, Lon: p.lat}, function(data) {
                        if (data == "y")
                        {
                            alert("保存成功！");
                        }
                        else
                        {
                            alert("保存失败！");
                        }

                    });
                }
            }

        </script>
    </body>
</html>